<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Call a header function</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.getservbyport.html">getservbyport</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.header-remove.html">header_remove</a></div>
 <div class="up"><a href="ref.network.html">Network 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.header-register-callback" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">header_register_callback</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">header_register_callback</span> &mdash; <span class="dc-title">Call a header function</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.header-register-callback-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>header_register_callback</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>
   )</div>

  <p class="para rdfs-comment">
   Registers a function that will be called when PHP starts sending output.
  </p>
  <p class="para">
   The <em><code class="parameter">callback</code></em> is executed just after PHP prepares all
   headers to be sent, and before any other output is sent, creating a window
   to manipulate the outgoing headers before being sent.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.header-register-callback-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">callback</code></em></dt>

    <dd>

     <p class="para">
      Function called just before the headers are sent. It gets no parameters
      and the return value is ignored.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.header-register-callback-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.header-register-callback-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="header-register-callback.example.basic">
   <p><strong>Example #1 <span class="function"><strong>header_register_callback()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type:&nbsp;text/plain'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'X-Test:&nbsp;foo'</span><span style="color: #007700">);<br /><br />function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">()&nbsp;{<br />&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">headers_list</span><span style="color: #007700">()&nbsp;as&nbsp;</span><span style="color: #0000BB">$header</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$header</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'X-Powered-By:'</span><span style="color: #007700">)&nbsp;!==&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">header_remove</span><span style="color: #007700">(</span><span style="color: #DD0000">'X-Powered-By'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">header_remove</span><span style="color: #007700">(</span><span style="color: #DD0000">'X-Test'</span><span style="color: #007700">);<br />&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">header_register_callback</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"a"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Content-Type: text/plain

a
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.header-register-callback-notes">
  <h3 class="title">注释</h3>
  <p class="para">
   <span class="function"><strong>header_register_callback()</strong></span> is executed just as the
   headers are about to be sent out, so any output from this function can
   break output.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
<p class="para">
 数据头只会在SAPI支持时得到处理和输出。
</p>
</p></blockquote>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.header-register-callback-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.headers-list.html" class="function" rel="rdfs-seeAlso">headers_list()</a> - Returns a list of response headers sent (or ready to send)</span></li>
   <li class="member"><span class="function"><a href="function.header-remove.html" class="function" rel="rdfs-seeAlso">header_remove()</a> - Remove previously set headers</span></li>
   <li class="member"><span class="function"><a href="function.header.html" class="function" rel="rdfs-seeAlso">header()</a> - Send a raw HTTP header</span></li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.getservbyport.html">getservbyport</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.header-remove.html">header_remove</a></div>
 <div class="up"><a href="ref.network.html">Network 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
